﻿using Entities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DA
{
    public class TaiKhoanDA:BaseConnection
    {
        public TaiKhoanDA()
        {

        }

        public TaiKhoan kiemTraTaiKhoan(string tenTaiKhoan, string matKhau)
        {
            TaiKhoan taiKhoan = null;
            openConnect();
            string sqlStm = "SELECT MaQuyen, MaPhongBan FROM TaiKhoan WHERE TenTaiKhoan=@tenTaiKhoan AND MatKhau=@matKhau";
            SqlCommand cmd = new SqlCommand(sqlStm, con);

            cmd.Parameters.Add("@tenTaiKhoan", SqlDbType.VarChar).Value = tenTaiKhoan;
            cmd.Parameters.Add("@matKhau", SqlDbType.VarChar).Value = matKhau;

            SqlDataReader dataReader = cmd.ExecuteReader();
            if (dataReader.HasRows && dataReader.Read())
            {
                
                //dataReader.NextResult();                
                taiKhoan = new TaiKhoan(tenTaiKhoan, Int16.Parse(dataReader[0].ToString()), Int16.Parse(dataReader[1].ToString()));                
            }
            dataReader.Close();
            return taiKhoan;            
        }
    }
}
